package com.itnoob.service1;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhoujun
 * @date 2025/3/27 00:05
 */

@Component
public class ConcreteMediator implements Mediator{

    //定义一个集合在存储bean对象
    private List<Object> beans = new ArrayList<>();

    @Override
    public void register(Object bean) {
        if (beans.size()   < 2){
            beans.add(bean);
        }
    }

    @Override
    public void relay(Object bean,String message){
        for (Object b : beans) {
            if (!b.equals(bean)){
                //根据消息类型调用相应的方法(这里简化成打印消息)
                System.out.println(b.getClass().getSimpleName() + "receive message: " + message );
            }
        }
    }
}
